﻿using System.Text;
using System.Collections;
using RAP.Framework.Libary.DomTemplateBuilder.Element.DictionaryActions.Add;
using RAP.Framework.Libary.DomTemplateBuilder.Interface;

namespace RAP.Framework.Libary.DomTemplateBuilder.Handler.DictionaryActions
{
	/// <summary>
	/// 字典的Handler
	/// </summary>
	public class DictionaryActionElementHandler : PropertyElementHandler
    {
        public new DictionaryAddActionElement Element
        {
            get
            {
                return base.Element as DictionaryAddActionElement;
            }
            set
            {
                base.Element = value;
            }
        }

        public override void DoRender( StringBuilder writer,
            object rootParamObject,
            object parentParamObject,
            ITemplateRenderContext context )
        {
			var paramObject = this.GetParamObject( rootParamObject, parentParamObject, context );
			var dict = context[ DictionaryActionHandler.DICTIONARY_OBJECT ] as IDictionary;
            if ( dict != null )
            {
				var actionWriter = new StringBuilder( );
                base.DoRender( actionWriter, rootParamObject, paramObject, context );
                this.DoAction( dict, writer, actionWriter, rootParamObject, paramObject, context );
            }
        }

        /// <summary>
        /// 指定对字典的操作动作
        /// </summary>
        /// <param name="dict"></param>
        /// <param name="writer"></param>
        public virtual void DoAction
        (
            IDictionary dict,
            StringBuilder writer,
            StringBuilder actionWriter,
            object rootParamObject,
            object parentParamObject,
            ITemplateRenderContext context
        )
        {

        }
    }
}
